package com.igeekhome.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeekhome.biz.BlackListService;
import com.igeekhome.biz.CustomerInfoService;
import com.igeekhome.pojo.BlackList;
import com.igeekhome.pojo.CustomerInfo;
import com.igeekhome.pojo.WorkOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 恶意用户列表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-03-16
 */
@Controller
@RequestMapping("/blackList")
public class BlackListController {
    @Autowired
    private BlackListController blackListController;
    @Autowired
    private BlackListService blackListService;

    @RequestMapping("/index")
    public String index(Model model, @RequestParam("current") Integer current, @RequestParam("size") Integer size){
        initblackListService(model,current,size);
        return "blacklist";
    }

    public void initblackListService(Model model, Integer current, Integer size)
    {

        IPage<BlackList> page=new Page<>(current,size);
        IPage<BlackList> page1 = this.blackListService.page(page);

        List<BlackList> list = page1.getRecords();
        long pagesCount = page1.getPages();


        model.addAttribute("list",list);
        model.addAttribute("pagesCount",pagesCount);
        model.addAttribute("main","黑名单页面");
    }


    @RequestMapping("/del")
    public String del(Model model,BlackList blackList,@RequestParam("current") Integer current, @RequestParam("size") Integer size){

//        customerServiceService.removeById(customerService.getCustomerserviceid());
//        IPage<CustomerService> page=new Page<>(current,size);
//        IPage<CustomerService> page1 = customerServiceService.page(page);
//        List<CustomerService> list = page1.getRecords();
//        model.addAttribute("list",list);

        this.blackListService.removeById(blackList.getId());
        initblackListService(model,current,size);

        return "blacklist";
    }

    @RequestMapping("/update")
    public String update(Model model, BlackList blackList,@RequestParam("current") Integer current, @RequestParam("size") Integer size)
    {
        // 根据id将对像查询
        blackList= this.blackListService.getById(blackList.getId());
        model.addAttribute("cs",blackList);
        model.addAttribute("main","客户修改");
        model.addAttribute("current",current);
        return  "updateblacklist";
    }


    @RequestMapping("/updcom")//修改完成
    public String updcom(BlackList blackList, Model model, @RequestParam("current") Integer current, @RequestParam("size") Integer size){
        System.out.println("能成功进入");
        BlackList cs = blackListService.getById(blackList);
        cs.setCustomerserviceid(blackList.getCustomerserviceid());
        cs.setCustomerid(blackList.getCustomerid());
        cs.setReason(blackList.getReason());
        cs.setTime(blackList.getTime());
        cs.setSource(blackList.getSource());
        cs.setId(blackList.getId());
        blackListService.updateById(cs);
        initblackListService(model,current,size);
        return "blacklist";
    }
    @RequestMapping("create")//创建订单界面
    public String create(){
        return "createblacklist";
    }
    @RequestMapping("createcom")//点击创建成功
    public String createcom(BlackList blackList, Model model){
        LocalDateTime localDateTime = LocalDateTime.now();
        model.addAttribute("localDateTime",localDateTime);
        blackList.setCreatetime(localDateTime);
        blackListService.save(blackList);
        model.addAttribute("main","工单管理页面");
        return "createblacklist";
    }
}

